package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusGoodsPrice;
import com.drug.wms.domain.BusPriceConf;
import com.drug.wms.service.IBusPriceConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 价格配置Controller
 *
 * @author ruoyi
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/wms/price")
public class BusPriceConfController extends BaseController {
    @Autowired
    private IBusPriceConfService busPriceConfService;

    /**
     * 查询价格配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusPriceConf busPriceConf) {
        startPage();
        List<BusPriceConf> list = busPriceConfService.selectBusPriceConfList(busPriceConf);
        return getDataTable(list);
    }

    /**
     * 查询价格配置列表
     */
    @GetMapping("/list/{goodsNo}")
    public AjaxResult listByGoodsNo(@PathVariable("goodsNo") String goodsNo) {
        List<BusGoodsPrice> list = busPriceConfService.selectBusGoodsPriceListByGoodsNo(goodsNo);
        return AjaxResult.success(list);
    }

    /**
     * 导出价格配置列表
     */
    @Log(title = "价格配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusPriceConf busPriceConf) {
        List<BusPriceConf> list = busPriceConfService.selectBusPriceConfList(busPriceConf);
        ExcelUtil<BusPriceConf> util = new ExcelUtil<BusPriceConf>(BusPriceConf.class);
        return util.exportExcel(list, "价格配置数据");
    }

    /**
     * 获取价格配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busPriceConfService.selectBusPriceConfById(id));
    }

    /**
     * 新增价格配置
     */
    @Log(title = "价格配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusPriceConf busPriceConf) {
        return toAjax(busPriceConfService.insertBusPriceConf(busPriceConf));
    }

    /**
     * 修改价格配置
     */
    @Log(title = "价格配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusPriceConf busPriceConf) {
        return toAjax(busPriceConfService.updateBusPriceConf(busPriceConf));
    }

    /**
     * 删除价格配置
     */
    @Log(title = "价格配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busPriceConfService.deleteBusPriceConfByIds(ids));
    }
}
